package net.qhzw.vip.qiyu.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.qhzw.vip.qiyu.entity.DtsBatteryStatus;
import net.qhzw.vip.qiyu.result.JsonResult;
import net.qhzw.vip.qiyu.service.DtsBatteryManageService;
import net.qhzw.vip.qiyu.service.DtsBatteryStatusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("dts/batteryrStatus")
@Api(tags = "电池状态状态维护管理")
public class DtsBatteryStatusController {



    @Autowired
    private DtsBatteryStatusService dtsBatteryStatusService;




    @ApiOperation(value = "分页查询电池状态维护")
    @GetMapping
    public JsonResult<Page<DtsBatteryStatus>> findByPage(Page<DtsBatteryStatus> page, DtsBatteryStatus dtsBatteryStatus) {
        //Long shopId = SecurityUtils.getLoginUser().getShopId();
        Page<DtsBatteryStatus> dtsBatteryStatusPage = dtsBatteryStatusService.findByPage(page, dtsBatteryStatus);
        return JsonResult.ok(dtsBatteryStatusPage);
    }

    @ApiOperation(value = "根据ID查询电池状态维护")
    @GetMapping("{id}")
    public JsonResult<DtsBatteryStatus> findDtsBatteryManage(@PathVariable Long id) {
        DtsBatteryStatus dtsBatteryManagePage = dtsBatteryStatusService.getById(id);
        return JsonResult.ok(dtsBatteryManagePage);
    }


    @ApiOperation(value = "添加电池状态信息")
    @PostMapping
    public JsonResult addDtsBatteryManage(@RequestBody DtsBatteryStatus dtsBatteryStatus) {

        boolean save = dtsBatteryStatusService.addDtsBatteryManage(dtsBatteryStatus);
        if (save) {
            return JsonResult.ok();
        }
        return JsonResult.fail();
    }


    @ApiOperation(value = "修改电池状态维护")
    @PutMapping
    public JsonResult updateDtsBatteryManage(@RequestBody DtsBatteryStatus dtsBatteryStatus) {
        boolean save = dtsBatteryStatusService.updateDtsBatteryManage(dtsBatteryStatus);
        if (save) {
            return JsonResult.ok();
        }
        return JsonResult.fail();
    }


    @ApiOperation(value = "设置电池状态维修状态")
    @PutMapping("setStatus")
    public JsonResult setStatus(@RequestBody DtsBatteryStatus dtsBatteryStatus) {
        boolean save = dtsBatteryStatusService.updateDtsBatteryManage(dtsBatteryStatus);
        if (save) {
            return JsonResult.ok();
        }
        return JsonResult.fail();
    }


    @ApiOperation(value = "删除电池状态维护")
    @DeleteMapping("{id}")
    public JsonResult<DtsBatteryStatus> findDtsBatteryManage(@PathVariable String id) {
        List<String> list = Arrays.asList(id.split(","));
        boolean remove = dtsBatteryStatusService.removeByIds(list);
        if (remove) {
            return JsonResult.ok();
        }
        return JsonResult.fail();
    }
    @ApiOperation(value = "查询电池状态维护")
    @GetMapping("/list")
    public JsonResult findByList() {
        List<DtsBatteryStatus> list = dtsBatteryStatusService.list(new LambdaQueryWrapper<DtsBatteryStatus>()
                .eq(DtsBatteryStatus::getIsDelete, 0));
        return JsonResult.ok(list);
    }




}
